package com.beself.service.impl;

import com.beself.dao.TMineMapper;
import com.beself.dao.TUserMapper;
import com.beself.entity.TUser;
import com.beself.service.UserService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

@Service
public class UserServiceImpl implements UserService {

    @Resource
    private TUserMapper tUserMapper;
    @Resource
    private TMineMapper tMineMapper;

    @Override
    public TUser findbyuUsername(String uTel) {
        TUser tUser = tUserMapper.findbyuUsername(uTel);
        if (tUser!=null)
        {
            return tUser;//代表注册过
        }
        return null;//代表没注册
    }

    //新增
    @Override
    public int insertUser(String uTel,String uPassword) {
        Map map=new HashMap();
        map.put("uTel",uTel);
        map.put("uPassword",uPassword);
        map.put("uUsername",uTel);
        System.out.println("map = " + map);
        int i = tUserMapper.insertUser(map);
        System.out.println("增加了i = " + i);
        return i;
    }

    @Override
    public TUser findbyUser(String uTel, String uPassword) {
        Map map=new HashMap();
        map.put("uTel",uTel);
        map.put("uPassword",uPassword);
        TUser tUser = tUserMapper.findbyUser(map);
        return tUser;
    }

    @Override
    public int updatemima(String uTel, String uPassword) {
        Map map=new HashMap();
        map.put("uTel",uTel);
        map.put("uPassword",uPassword);
        int updatemima = tUserMapper.updatemima(map);
        return updatemima;
    }

    //根据新增id增加mine表中的u_id进行关联
    @Override
    public int insertuserid(int uId) {
        Map map=new HashMap();
        map.put("uId",uId);
        System.out.println("map = " + map);
        int insertuserid = tMineMapper.insertuserid(map);
        System.out.println("insertuserid,service = " + insertuserid);
        return insertuserid;
    }


}
